#include "pch.h"
#include<iostream>
#include <regex>
#include "common.h"
#include <fstream>
using namespace std;
#ifdef DEBUG
extern ofstream out;
#endif
void parsePureNumber(std::string& str)
{
#ifdef DEBUG
	out << "str1 " << str << endl;
#endif
	if (str.empty())
	{
		return;
	}
	std::smatch sresult;
	std::vector<pair<string, string> >results;
	string pattern = "-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?";
	std::regex reg(pattern);
	if (!std::regex_search(str, sresult, reg))
	{
		return;
	}
#ifdef DEBUG
	out << sresult.str() << endl;
	out << "str2 " << str << endl;
#endif
	str = sresult.str();

}
int parseSingleStrPair(std::string str, std::regex reg, std::vector<pair<std::string, std::string>>& m_vPair)
{
	if (!std::regex_search(str, reg))
	{
		return -1;
	}
	sregex_token_iterator p(str.cbegin(), str.cend(), reg, { -1,0 });
	sregex_token_iterator ptr = p;
	sregex_token_iterator end;
	int i = 0;
	std::string first = "";
	std::string second = "";
	for (; ptr != end; ptr++)
	{
		if (ptr == p)
			continue;
		if (i % 2) {
			second = ptr->str();
			m_vPair.push_back(make_pair(first, second));
		}
		else {
			first = ptr->str();
			if (std::next(ptr) == end)
			{
				m_vPair.push_back(make_pair(first, ""));
			}
		}
		i++;
	}
	return 0;
}